package com.console.operations.fundmgr;

import java.math.BigDecimal;

import org.testng.Assert;

import com.common.test.OperationBase;
import com.common.test.UITestBase;
import com.common.util.DBUtil;
import com.console.pages.fundmgr.WithdrawTwoPage;


public class WithdrawTwo extends OperationBase {

	public WithdrawTwo(UITestBase tb){
		super(tb);
	}
	
	public void TwoTrial() throws Exception{
		//进入提现终审页面
		switchToDefaultContent();
		WithdrawTwoPage wtp = new WithdrawTwoPage(tb);
		waitForElementExist(wtp.cashpage);	
		wtp.cashpage.click();
		waitForElementExist(wtp.WithdrawTwo);
		wtp.WithdrawTwo.click();
		waitForElementExist(wtp.WithdrawTwoNo);
		//获取提现编号
		String wtn = wtp.WithdrawTwoNo.getText();
		System.out.println("提现编号是："+wtn);
		//查看用户冻结余额和提现资金以及手续费
		String wtbalance=DBUtil.queryOneCell("SELECT "
				+ "a.nb_balance "
				+ "from fiz_user_account a,fiz_withdraw b "
				+ "where "
				+ "a.fk_user_id=b.fk_user_id "
				+ "and dc_type='99'"
				+ "and vc_batch= ?", new Object[]{wtn});
		BigDecimal i = new BigDecimal(wtbalance);//转成BigDecimal
		System.out.println("用户冻结资金是："+i);
		String wtcash=DBUtil.queryOneCell("select nb_amount from fiz_withdraw where vc_batch = ?", new Object[]{wtn});
		BigDecimal y = new BigDecimal(wtcash);
		System.out.println("用户提现资金是："+y);
		String wtfee=DBUtil.queryOneCell("select nb_fee from fiz_withdraw where vc_batch = ?", new Object[]{wtn});
		System.out.println("用户提现手续费是："+wtfee);
		BigDecimal f = new BigDecimal(wtfee);
		BigDecimal yf=y.add(f);//提现资金加手续费
		//点击终审通过
		wtp.TwoSummry.click();
		waitForElementExist(wtp.TwoPass);
		wtp.TwoPass.click();
		waitForElementExist(wtp.TwoConfirmPass);
		wtp.TwoConfirmPass.click();
		waitForElementExist(wtp.TwoConfirmInfo);
		//验证终审通过
		String tci = wtp.TwoConfirmInfo.getText();
		System.out.println("获得返回信息是："+tci);
		Assert.assertEquals(tci,"终审通过");
		//验证提现状态是否变化
		String wts=DBUtil.queryOneCell("select dc_status from fiz_withdraw where vc_batch = ?", new Object[]{wtn});
		System.out.println("数据库查询状态为："+wts);
		Assert.assertEquals(wts,"10");
		//验证冻结资金变化
		BigDecimal wtbalancechange =i.subtract(yf);
		System.out.println("用户提现后预期冻结资金是："+wtbalancechange);	
		String wtbalanceto=DBUtil.queryOneCell("SELECT "
				+ "a.nb_balance "
				+ "from fiz_user_account a,fiz_withdraw b "
				+ "where "
				+ "a.fk_user_id=b.fk_user_id "
				+ "and dc_type='99'"
				+ "and vc_batch= ?", new Object[]{wtn});
		BigDecimal e = new BigDecimal(wtbalanceto);
		System.out.println("用户提现后冻结资金是："+e);		
		Assert.assertEquals(wtbalancechange,e);
	}
}
